<?php

namespace backend\models;

use common\models\User;
use Yii;

/**
 * This is the model class for table "news_nom".
 *
 * @property integer $id
 * @property string $title
 * @property string $summary
 * @property string $content
 * @property string $tags
 * @property integer $authorid
 * @property string $authorname
 * @property string $image
 * @property integer $status
 * @property integer $up
 * @property string $ptime
 * @property integer $userid
 * @property string $username
 * @property integer $ctime
 * @property integer $mtime
 */
class NewsNom extends \yii\db\ActiveRecord
{
    const NEWS_STATUS_ALL = null; //所有
    const NEWS_STATUS_NOM = 0; //正常
    const NEWS_STATUS_DEL = 1; //已删除
    const NEWS_STATUS_DRA = 2; //草稿
    const NEWS_STATUS_WAT = 3; //定时中
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'news_nom';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title','image','summary','content', 'authorid','tags','status'], 'required'],
            [['content'], 'string'],
            [['authorid', 'status', 'up', 'userid', 'ctime', 'mtime'], 'integer'],
            [['ptime'], 'safe'],
            [['title', 'tags', 'image'], 'string', 'max' => 500],
            [['summary'], 'string', 'max' => 1000],
            [['authorname', 'username'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '文章标题',
            'summary' => '文章摘要',
            'content' => '文章正文',
            'tags' => '文章标签',
            'authorid' => '文章作者',
            'authorname' => '文章作者',
            'image' => '作品题图',
            'status' => '状态',
            'up' => '点赞',
            'ptime' => '发布时间',
            'userid' => '创建者',
            'username' => '创建者',
            'ctime' => '创建时间',
            'mtime' => '修改时间',
        ];
    }

    public function getUserInfo(){
        return $this->hasOne(UserInfo::className(), ['userid' => 'authorid']);
    }
}
